﻿using EnvDTE;
using EnvDTE80;
using Microsoft.Practices.RecipeFramework;
using ProjectBase.Guidance.Helpers;

namespace ProjectBase.Guidance.Actions
{
    public class SetStartProjectAction : Action
    {
        [Input(Required = true)]
        public string ProjectName { get; set; }

        public override void Execute()
        {
            var dte = (DTE) GetService(typeof (DTE));
            var dte2 = (DTE2) dte;
            var soln = (Solution2) dte2.Solution;
            var solnBld = (SolutionBuild2) soln.SolutionBuild;

            Project project = SolutionHelper.FindProjectByName(dte, ProjectName);

            solnBld.StartupProjects = project.UniqueName;

            project.Properties.Item("WebApplication.DebugStartAction").Value = 1;
            project.Properties.Item("WebApplication.StartPageUrl").Value = "Index.htm";
        }

        public override void Undo()
        {
        }
    }
}